package com.leetcode.LC;

public class LC05 {
    private static int maxLength=1,start=0;
    public static String longestPalindrome(String s) {
        if (s.length() < 2) {
            return s;
        }
        for (int i = 0; i < s.length(); i++) {
            expandAroundCenter(s,i-1,i+1);
            expandAroundCenter(s,i,i+1);
        }

        return s.substring(start,start+maxLength);
    }

    private static void expandAroundCenter(String s, int left, int right){
        char[] chars = s.toCharArray();
        while (left>=0&&right<s.length()&&chars[left]==chars[right]){
            // 更新到更大的maxLength
            if(right-left+1>maxLength){
                maxLength=right-left+1;
                start=left;
            }
            left--;
            right++;
        }
    }

    public static void main(String[] args) {
        String abc = longestPalindrome("cbbd");
        System.out.println(abc);

    }
}
